<?php

/**
 * Quản trị hệ thống liên hệ
 *
 * @version $Rev:$
 * @license
 */
class Contact_AdminController extends Zend_Controller_Action
{

    public function init()
    {
        $this->params = $this->getRequest()->getParams();
        System_Template::using("blank","Admin");
        $this->model = new Contact_Model_Admin();
        parent::init();
    }
    /**
    * Danh sách các liên hệ
    */
    public function indexAction()
    {
    	common::showButton('delete');
		$result = $this->model->selectListMessage();
		$this->view->data = $result;	
	}
    /**
    * Xóa liên hệ
    */
    public function deleteAction()
    {
    	$id_dels = $this->params['DEL'];
    	foreach($id_dels as $id){
    		$result = $this->model->deleteMessage($id);	
    	}
    	ajax::ship('result','1');
		//$this->_redirect('contact/admin/index');
		//exit;
    }

    public function viewAction()
    {
    	common::showButton('back');
    	$id_message = $this->params['id'];
    	$view = $this->model->viewMessage($id_message);
    	$this->model->updateIsread($id_message);
    	$this->view->viewmessage = $view;
    	//ajax::ship('success',$id_contact);
    }
	/**
    * Gửi mail liên hệ
    */
	public function sendmailAction()
    {
    	
    	$usermail = $this->params['USERMAIL'];
    	$ex = explode("(",$usermail);
    	$exname = explode(")",$ex[1]);
    	$data = array(
    		'USERMAIL' => $ex[0],
    		'CONTENT' => $this->params['CONTENT'],
    		'ALIASMAIL' => $exname[0],
    	);
    	Plugin::sendMail($data);
    }
	
}

